﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using BesAsm.MasterData.Entities;
using BesAsm.MasterData.Data;

#endregion

namespace BesAsm.MasterData.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="SanPatternProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class SanPatternProviderBaseCore : EntityProviderBase<BesAsm.MasterData.Entities.SanPattern, BesAsm.MasterData.Entities.SanPatternKey>
	{		
		#region Get from Many To Many Relationship Functions
		#endregion	
		
		#region Delete Methods

		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to delete.</param>
		/// <returns>Returns true if operation suceeded.</returns>
		public override bool Delete(TransactionManager transactionManager, BesAsm.MasterData.Entities.SanPatternKey key)
		{
			return Delete(transactionManager, key.SanPatternId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="_sanPatternId">Primary key, sanitary pattern Id. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public bool Delete(System.Int32 _sanPatternId)
		{
			return Delete(null, _sanPatternId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_sanPatternId">Primary key, sanitary pattern Id. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public abstract bool Delete(TransactionManager transactionManager, System.Int32 _sanPatternId);		
		
		#endregion Delete Methods
		
		#region Get By Foreign Key Functions
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_SAN_PATTERNS_STATUSES key.
		///		FK_SAN_PATTERNS_STATUSES Description: 
		/// </summary>
		/// <param name="_status">Status of record, in terms of usability for further analysis and general state of data</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SanPattern objects.</returns>
		public TList<SanPattern> GetByStatus(System.String _status)
		{
			int count = -1;
			return GetByStatus(_status, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_SAN_PATTERNS_STATUSES key.
		///		FK_SAN_PATTERNS_STATUSES Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_status">Status of record, in terms of usability for further analysis and general state of data</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SanPattern objects.</returns>
		/// <remarks></remarks>
		public TList<SanPattern> GetByStatus(TransactionManager transactionManager, System.String _status)
		{
			int count = -1;
			return GetByStatus(transactionManager, _status, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_SAN_PATTERNS_STATUSES key.
		///		FK_SAN_PATTERNS_STATUSES Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_status">Status of record, in terms of usability for further analysis and general state of data</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SanPattern objects.</returns>
		public TList<SanPattern> GetByStatus(TransactionManager transactionManager, System.String _status, int start, int pageLength)
		{
			int count = -1;
			return GetByStatus(transactionManager, _status, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_SAN_PATTERNS_STATUSES key.
		///		fkSanPatternsStatuses Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_status">Status of record, in terms of usability for further analysis and general state of data</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SanPattern objects.</returns>
		public TList<SanPattern> GetByStatus(System.String _status, int start, int pageLength)
		{
			int count =  -1;
			return GetByStatus(null, _status, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_SAN_PATTERNS_STATUSES key.
		///		fkSanPatternsStatuses Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_status">Status of record, in terms of usability for further analysis and general state of data</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SanPattern objects.</returns>
		public TList<SanPattern> GetByStatus(System.String _status, int start, int pageLength,out int count)
		{
			return GetByStatus(null, _status, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_SAN_PATTERNS_STATUSES key.
		///		FK_SAN_PATTERNS_STATUSES Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_status">Status of record, in terms of usability for further analysis and general state of data</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of BesAsm.MasterData.Entities.SanPattern objects.</returns>
		public abstract TList<SanPattern> GetByStatus(TransactionManager transactionManager, System.String _status, int start, int pageLength, out int count);
		
		#endregion

		#region Get By Index Functions
		
		/// <summary>
		/// 	Gets a row from the DataSource based on its primary key.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to retrieve.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <returns>Returns an instance of the Entity class.</returns>
		public override BesAsm.MasterData.Entities.SanPattern Get(TransactionManager transactionManager, BesAsm.MasterData.Entities.SanPatternKey key, int start, int pageLength)
		{
			return GetBySanPatternId(transactionManager, key.SanPatternId, start, pageLength);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key PK_SAN_PATTERNS index.
		/// </summary>
		/// <param name="_sanPatternId">Primary key, sanitary pattern Id</param>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.SanPattern"/> class.</returns>
		public BesAsm.MasterData.Entities.SanPattern GetBySanPatternId(System.Int32 _sanPatternId)
		{
			int count = -1;
			return GetBySanPatternId(null,_sanPatternId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_SAN_PATTERNS index.
		/// </summary>
		/// <param name="_sanPatternId">Primary key, sanitary pattern Id</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.SanPattern"/> class.</returns>
		public BesAsm.MasterData.Entities.SanPattern GetBySanPatternId(System.Int32 _sanPatternId, int start, int pageLength)
		{
			int count = -1;
			return GetBySanPatternId(null, _sanPatternId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_SAN_PATTERNS index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_sanPatternId">Primary key, sanitary pattern Id</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.SanPattern"/> class.</returns>
		public BesAsm.MasterData.Entities.SanPattern GetBySanPatternId(TransactionManager transactionManager, System.Int32 _sanPatternId)
		{
			int count = -1;
			return GetBySanPatternId(transactionManager, _sanPatternId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_SAN_PATTERNS index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_sanPatternId">Primary key, sanitary pattern Id</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.SanPattern"/> class.</returns>
		public BesAsm.MasterData.Entities.SanPattern GetBySanPatternId(TransactionManager transactionManager, System.Int32 _sanPatternId, int start, int pageLength)
		{
			int count = -1;
			return GetBySanPatternId(transactionManager, _sanPatternId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_SAN_PATTERNS index.
		/// </summary>
		/// <param name="_sanPatternId">Primary key, sanitary pattern Id</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.SanPattern"/> class.</returns>
		public BesAsm.MasterData.Entities.SanPattern GetBySanPatternId(System.Int32 _sanPatternId, int start, int pageLength, out int count)
		{
			return GetBySanPatternId(null, _sanPatternId, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_SAN_PATTERNS index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_sanPatternId">Primary key, sanitary pattern Id</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="BesAsm.MasterData.Entities.SanPattern"/> class.</returns>
		public abstract BesAsm.MasterData.Entities.SanPattern GetBySanPatternId(TransactionManager transactionManager, System.Int32 _sanPatternId, int start, int pageLength, out int count);
						
		#endregion "Get By Index Functions"
	
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions	
		
		/// <summary>
		/// Fill a TList&lt;SanPattern&gt; From a DataReader.
		/// </summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">number of rows.</param>
		/// <returns>a <see cref="TList&lt;SanPattern&gt;"/></returns>
		public static TList<SanPattern> Fill(IDataReader reader, TList<SanPattern> rows, int start, int pageLength)
		{
			NetTiersProvider currentProvider = DataRepository.Provider;
            bool useEntityFactory = currentProvider.UseEntityFactory;
            bool enableEntityTracking = currentProvider.EnableEntityTracking;
            LoadPolicy currentLoadPolicy = currentProvider.CurrentLoadPolicy;
			Type entityCreationFactoryType = currentProvider.EntityCreationalFactoryType;
			
			// advance to the starting row
			for (int i = 0; i < start; i++)
			{
				if (!reader.Read())
				return rows; // not enough rows, just return
			}
			for (int i = 0; i < pageLength; i++)
			{
				if (!reader.Read())
					break; // we are done
					
				string key = null;
				
				BesAsm.MasterData.Entities.SanPattern c = null;
				if (useEntityFactory)
				{
					key = new System.Text.StringBuilder("SanPattern")
					.Append("|").Append((System.Int32)reader[((int)SanPatternColumn.SanPatternId - 1)]).ToString();
					c = EntityManager.LocateOrCreate<SanPattern>(
					key.ToString(), // EntityTrackingKey
					"SanPattern",  //Creational Type
					entityCreationFactoryType,  //Factory used to create entity
					enableEntityTracking); // Track this entity?
				}
				else
				{
					c = new BesAsm.MasterData.Entities.SanPattern();
				}
				
				if (!enableEntityTracking ||
					c.EntityState == EntityState.Added ||
					(enableEntityTracking &&
					
						(
							(currentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
							(currentLoadPolicy == LoadPolicy.DiscardChanges && c.EntityState != EntityState.Unchanged)
						)
					))
				{
					c.SuppressEntityEvents = true;
					c.SanPatternId = (System.Int32)reader[((int)SanPatternColumn.SanPatternId - 1)];
					c.OriginalSanPatternId = c.SanPatternId;
					c.Name = (reader.IsDBNull(((int)SanPatternColumn.Name - 1)))?null:(System.String)reader[((int)SanPatternColumn.Name - 1)];
					c.Instance = (reader.IsDBNull(((int)SanPatternColumn.Instance - 1)))?null:(System.Int32?)reader[((int)SanPatternColumn.Instance - 1)];
					c.H1 = (reader.IsDBNull(((int)SanPatternColumn.H1 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H1 - 1)];
					c.H2 = (reader.IsDBNull(((int)SanPatternColumn.H2 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H2 - 1)];
					c.H3 = (reader.IsDBNull(((int)SanPatternColumn.H3 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H3 - 1)];
					c.H4 = (reader.IsDBNull(((int)SanPatternColumn.H4 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H4 - 1)];
					c.H5 = (reader.IsDBNull(((int)SanPatternColumn.H5 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H5 - 1)];
					c.H6 = (reader.IsDBNull(((int)SanPatternColumn.H6 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H6 - 1)];
					c.H7 = (reader.IsDBNull(((int)SanPatternColumn.H7 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H7 - 1)];
					c.H8 = (reader.IsDBNull(((int)SanPatternColumn.H8 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H8 - 1)];
					c.H9 = (reader.IsDBNull(((int)SanPatternColumn.H9 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H9 - 1)];
					c.H10 = (reader.IsDBNull(((int)SanPatternColumn.H10 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H10 - 1)];
					c.H11 = (reader.IsDBNull(((int)SanPatternColumn.H11 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H11 - 1)];
					c.H12 = (reader.IsDBNull(((int)SanPatternColumn.H12 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H12 - 1)];
					c.H13 = (reader.IsDBNull(((int)SanPatternColumn.H13 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H13 - 1)];
					c.H14 = (reader.IsDBNull(((int)SanPatternColumn.H14 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H14 - 1)];
					c.H15 = (reader.IsDBNull(((int)SanPatternColumn.H15 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H15 - 1)];
					c.H16 = (reader.IsDBNull(((int)SanPatternColumn.H16 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H16 - 1)];
					c.H17 = (reader.IsDBNull(((int)SanPatternColumn.H17 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H17 - 1)];
					c.H18 = (reader.IsDBNull(((int)SanPatternColumn.H18 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H18 - 1)];
					c.H19 = (reader.IsDBNull(((int)SanPatternColumn.H19 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H19 - 1)];
					c.H20 = (reader.IsDBNull(((int)SanPatternColumn.H20 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H20 - 1)];
					c.H21 = (reader.IsDBNull(((int)SanPatternColumn.H21 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H21 - 1)];
					c.H22 = (reader.IsDBNull(((int)SanPatternColumn.H22 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H22 - 1)];
					c.H23 = (reader.IsDBNull(((int)SanPatternColumn.H23 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H23 - 1)];
					c.H24 = (reader.IsDBNull(((int)SanPatternColumn.H24 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H24 - 1)];
					c.Sunday = (reader.IsDBNull(((int)SanPatternColumn.Sunday - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.Sunday - 1)];
					c.Monday = (reader.IsDBNull(((int)SanPatternColumn.Monday - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.Monday - 1)];
					c.Tuesday = (reader.IsDBNull(((int)SanPatternColumn.Tuesday - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.Tuesday - 1)];
					c.Wednesday = (reader.IsDBNull(((int)SanPatternColumn.Wednesday - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.Wednesday - 1)];
					c.Thursday = (reader.IsDBNull(((int)SanPatternColumn.Thursday - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.Thursday - 1)];
					c.Friday = (reader.IsDBNull(((int)SanPatternColumn.Friday - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.Friday - 1)];
					c.Saturday = (reader.IsDBNull(((int)SanPatternColumn.Saturday - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.Saturday - 1)];
					c.EditedBy = (System.String)reader[((int)SanPatternColumn.EditedBy - 1)];
					c.EditReason = (System.String)reader[((int)SanPatternColumn.EditReason - 1)];
					c.Status = (reader.IsDBNull(((int)SanPatternColumn.Status - 1)))?null:(System.String)reader[((int)SanPatternColumn.Status - 1)];
					c.AppendDate = (System.DateTime)reader[((int)SanPatternColumn.AppendDate - 1)];
					c.EditDate = (reader.IsDBNull(((int)SanPatternColumn.EditDate - 1)))?null:(System.DateTime?)reader[((int)SanPatternColumn.EditDate - 1)];
					c.EntityTrackingKey = key;
					c.AcceptChanges();
					c.SuppressEntityEvents = false;
				}
				rows.Add(c);
			}
		return rows;
		}		
		/// <summary>
		/// Refreshes the <see cref="BesAsm.MasterData.Entities.SanPattern"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="BesAsm.MasterData.Entities.SanPattern"/> object to refresh.</param>
		public static void RefreshEntity(IDataReader reader, BesAsm.MasterData.Entities.SanPattern entity)
		{
			if (!reader.Read()) return;
			
			entity.SanPatternId = (System.Int32)reader[((int)SanPatternColumn.SanPatternId - 1)];
			entity.OriginalSanPatternId = (System.Int32)reader["san_pattern_id"];
			entity.Name = (reader.IsDBNull(((int)SanPatternColumn.Name - 1)))?null:(System.String)reader[((int)SanPatternColumn.Name - 1)];
			entity.Instance = (reader.IsDBNull(((int)SanPatternColumn.Instance - 1)))?null:(System.Int32?)reader[((int)SanPatternColumn.Instance - 1)];
			entity.H1 = (reader.IsDBNull(((int)SanPatternColumn.H1 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H1 - 1)];
			entity.H2 = (reader.IsDBNull(((int)SanPatternColumn.H2 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H2 - 1)];
			entity.H3 = (reader.IsDBNull(((int)SanPatternColumn.H3 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H3 - 1)];
			entity.H4 = (reader.IsDBNull(((int)SanPatternColumn.H4 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H4 - 1)];
			entity.H5 = (reader.IsDBNull(((int)SanPatternColumn.H5 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H5 - 1)];
			entity.H6 = (reader.IsDBNull(((int)SanPatternColumn.H6 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H6 - 1)];
			entity.H7 = (reader.IsDBNull(((int)SanPatternColumn.H7 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H7 - 1)];
			entity.H8 = (reader.IsDBNull(((int)SanPatternColumn.H8 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H8 - 1)];
			entity.H9 = (reader.IsDBNull(((int)SanPatternColumn.H9 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H9 - 1)];
			entity.H10 = (reader.IsDBNull(((int)SanPatternColumn.H10 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H10 - 1)];
			entity.H11 = (reader.IsDBNull(((int)SanPatternColumn.H11 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H11 - 1)];
			entity.H12 = (reader.IsDBNull(((int)SanPatternColumn.H12 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H12 - 1)];
			entity.H13 = (reader.IsDBNull(((int)SanPatternColumn.H13 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H13 - 1)];
			entity.H14 = (reader.IsDBNull(((int)SanPatternColumn.H14 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H14 - 1)];
			entity.H15 = (reader.IsDBNull(((int)SanPatternColumn.H15 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H15 - 1)];
			entity.H16 = (reader.IsDBNull(((int)SanPatternColumn.H16 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H16 - 1)];
			entity.H17 = (reader.IsDBNull(((int)SanPatternColumn.H17 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H17 - 1)];
			entity.H18 = (reader.IsDBNull(((int)SanPatternColumn.H18 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H18 - 1)];
			entity.H19 = (reader.IsDBNull(((int)SanPatternColumn.H19 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H19 - 1)];
			entity.H20 = (reader.IsDBNull(((int)SanPatternColumn.H20 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H20 - 1)];
			entity.H21 = (reader.IsDBNull(((int)SanPatternColumn.H21 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H21 - 1)];
			entity.H22 = (reader.IsDBNull(((int)SanPatternColumn.H22 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H22 - 1)];
			entity.H23 = (reader.IsDBNull(((int)SanPatternColumn.H23 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H23 - 1)];
			entity.H24 = (reader.IsDBNull(((int)SanPatternColumn.H24 - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.H24 - 1)];
			entity.Sunday = (reader.IsDBNull(((int)SanPatternColumn.Sunday - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.Sunday - 1)];
			entity.Monday = (reader.IsDBNull(((int)SanPatternColumn.Monday - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.Monday - 1)];
			entity.Tuesday = (reader.IsDBNull(((int)SanPatternColumn.Tuesday - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.Tuesday - 1)];
			entity.Wednesday = (reader.IsDBNull(((int)SanPatternColumn.Wednesday - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.Wednesday - 1)];
			entity.Thursday = (reader.IsDBNull(((int)SanPatternColumn.Thursday - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.Thursday - 1)];
			entity.Friday = (reader.IsDBNull(((int)SanPatternColumn.Friday - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.Friday - 1)];
			entity.Saturday = (reader.IsDBNull(((int)SanPatternColumn.Saturday - 1)))?null:(System.Decimal?)reader[((int)SanPatternColumn.Saturday - 1)];
			entity.EditedBy = (System.String)reader[((int)SanPatternColumn.EditedBy - 1)];
			entity.EditReason = (System.String)reader[((int)SanPatternColumn.EditReason - 1)];
			entity.Status = (reader.IsDBNull(((int)SanPatternColumn.Status - 1)))?null:(System.String)reader[((int)SanPatternColumn.Status - 1)];
			entity.AppendDate = (System.DateTime)reader[((int)SanPatternColumn.AppendDate - 1)];
			entity.EditDate = (reader.IsDBNull(((int)SanPatternColumn.EditDate - 1)))?null:(System.DateTime?)reader[((int)SanPatternColumn.EditDate - 1)];
			entity.AcceptChanges();
		}
		
		/// <summary>
		/// Refreshes the <see cref="BesAsm.MasterData.Entities.SanPattern"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="BesAsm.MasterData.Entities.SanPattern"/> object.</param>
		public static void RefreshEntity(DataSet dataSet, BesAsm.MasterData.Entities.SanPattern entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.SanPatternId = (System.Int32)dataRow["san_pattern_id"];
			entity.OriginalSanPatternId = (System.Int32)dataRow["san_pattern_id"];
			entity.Name = Convert.IsDBNull(dataRow["name"]) ? null : (System.String)dataRow["name"];
			entity.Instance = Convert.IsDBNull(dataRow["instance"]) ? null : (System.Int32?)dataRow["instance"];
			entity.H1 = Convert.IsDBNull(dataRow["h1"]) ? null : (System.Decimal?)dataRow["h1"];
			entity.H2 = Convert.IsDBNull(dataRow["h2"]) ? null : (System.Decimal?)dataRow["h2"];
			entity.H3 = Convert.IsDBNull(dataRow["h3"]) ? null : (System.Decimal?)dataRow["h3"];
			entity.H4 = Convert.IsDBNull(dataRow["h4"]) ? null : (System.Decimal?)dataRow["h4"];
			entity.H5 = Convert.IsDBNull(dataRow["h5"]) ? null : (System.Decimal?)dataRow["h5"];
			entity.H6 = Convert.IsDBNull(dataRow["h6"]) ? null : (System.Decimal?)dataRow["h6"];
			entity.H7 = Convert.IsDBNull(dataRow["h7"]) ? null : (System.Decimal?)dataRow["h7"];
			entity.H8 = Convert.IsDBNull(dataRow["h8"]) ? null : (System.Decimal?)dataRow["h8"];
			entity.H9 = Convert.IsDBNull(dataRow["h9"]) ? null : (System.Decimal?)dataRow["h9"];
			entity.H10 = Convert.IsDBNull(dataRow["h10"]) ? null : (System.Decimal?)dataRow["h10"];
			entity.H11 = Convert.IsDBNull(dataRow["h11"]) ? null : (System.Decimal?)dataRow["h11"];
			entity.H12 = Convert.IsDBNull(dataRow["h12"]) ? null : (System.Decimal?)dataRow["h12"];
			entity.H13 = Convert.IsDBNull(dataRow["h13"]) ? null : (System.Decimal?)dataRow["h13"];
			entity.H14 = Convert.IsDBNull(dataRow["h14"]) ? null : (System.Decimal?)dataRow["h14"];
			entity.H15 = Convert.IsDBNull(dataRow["h15"]) ? null : (System.Decimal?)dataRow["h15"];
			entity.H16 = Convert.IsDBNull(dataRow["h16"]) ? null : (System.Decimal?)dataRow["h16"];
			entity.H17 = Convert.IsDBNull(dataRow["h17"]) ? null : (System.Decimal?)dataRow["h17"];
			entity.H18 = Convert.IsDBNull(dataRow["h18"]) ? null : (System.Decimal?)dataRow["h18"];
			entity.H19 = Convert.IsDBNull(dataRow["h19"]) ? null : (System.Decimal?)dataRow["h19"];
			entity.H20 = Convert.IsDBNull(dataRow["h20"]) ? null : (System.Decimal?)dataRow["h20"];
			entity.H21 = Convert.IsDBNull(dataRow["h21"]) ? null : (System.Decimal?)dataRow["h21"];
			entity.H22 = Convert.IsDBNull(dataRow["h22"]) ? null : (System.Decimal?)dataRow["h22"];
			entity.H23 = Convert.IsDBNull(dataRow["h23"]) ? null : (System.Decimal?)dataRow["h23"];
			entity.H24 = Convert.IsDBNull(dataRow["h24"]) ? null : (System.Decimal?)dataRow["h24"];
			entity.Sunday = Convert.IsDBNull(dataRow["sunday"]) ? null : (System.Decimal?)dataRow["sunday"];
			entity.Monday = Convert.IsDBNull(dataRow["monday"]) ? null : (System.Decimal?)dataRow["monday"];
			entity.Tuesday = Convert.IsDBNull(dataRow["tuesday"]) ? null : (System.Decimal?)dataRow["tuesday"];
			entity.Wednesday = Convert.IsDBNull(dataRow["wednesday"]) ? null : (System.Decimal?)dataRow["wednesday"];
			entity.Thursday = Convert.IsDBNull(dataRow["thursday"]) ? null : (System.Decimal?)dataRow["thursday"];
			entity.Friday = Convert.IsDBNull(dataRow["friday"]) ? null : (System.Decimal?)dataRow["friday"];
			entity.Saturday = Convert.IsDBNull(dataRow["saturday"]) ? null : (System.Decimal?)dataRow["saturday"];
			entity.EditedBy = (System.String)dataRow["edited_by"];
			entity.EditReason = (System.String)dataRow["edit_reason"];
			entity.Status = Convert.IsDBNull(dataRow["status"]) ? null : (System.String)dataRow["status"];
			entity.AppendDate = (System.DateTime)dataRow["append_date"];
			entity.EditDate = Convert.IsDBNull(dataRow["edit_date"]) ? null : (System.DateTime?)dataRow["edit_date"];
			entity.AcceptChanges();
		}
		#endregion 
		
		#region DeepLoad Methods
		/// <summary>
		/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
		/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
		/// </summary>
		/// <remarks>
		/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
		/// </remarks>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">The <see cref="BesAsm.MasterData.Entities.SanPattern"/> object to load.</param>
		/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
		/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
		/// <param name="childTypes">BesAsm.MasterData.Entities.SanPattern Property Collection Type Array To Include or Exclude from Load</param>
		/// <param name="innerList">A collection of child types for easy access.</param>
	    /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception>
	    /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception>
		public override void DeepLoad(TransactionManager transactionManager, BesAsm.MasterData.Entities.SanPattern entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList)
		{
			if(entity == null)
				return;

			#region StatusSource	
			if (CanDeepLoad(entity, "Status|StatusSource", deepLoadType, innerList) 
				&& entity.StatusSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = (entity.Status ?? string.Empty);
				Status tmpEntity = EntityManager.LocateEntity<Status>(EntityLocator.ConstructKeyFromPkItems(typeof(Status), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.StatusSource = tmpEntity;
				else
					entity.StatusSource = DataRepository.StatusProvider.GetByStatusId(transactionManager, (entity.Status ?? string.Empty));		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'StatusSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.StatusSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.StatusProvider.DeepLoad(transactionManager, entity.StatusSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion StatusSource
			
			//used to hold DeepLoad method delegates and fire after all the local children have been loaded.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			
			//Fire all DeepLoad Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			deepHandles = null;
		}
		
		#endregion 
		
		#region DeepSave Methods

		/// <summary>
		/// Deep Save the entire object graph of the BesAsm.MasterData.Entities.SanPattern object with criteria based of the child 
		/// Type property array and DeepSaveType.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="entity">BesAsm.MasterData.Entities.SanPattern instance</param>
		/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
		/// <param name="childTypes">BesAsm.MasterData.Entities.SanPattern Property Collection Type Array To Include or Exclude from Save</param>
		/// <param name="innerList">A Hashtable of child types for easy access.</param>
		public override bool DeepSave(TransactionManager transactionManager, BesAsm.MasterData.Entities.SanPattern entity, DeepSaveType deepSaveType, System.Type[] childTypes, DeepSession innerList)
		{	
			if (entity == null)
				return false;
							
			#region Composite Parent Properties
			//Save Source Composite Properties, however, don't call deep save on them.  
			//So they only get saved a single level deep.
			
			#region StatusSource
			if (CanDeepSave(entity, "Status|StatusSource", deepSaveType, innerList) 
				&& entity.StatusSource != null)
			{
				DataRepository.StatusProvider.Save(transactionManager, entity.StatusSource);
				entity.Status = entity.StatusSource.StatusId;
			}
			#endregion 
			#endregion Composite Parent Properties

			// Save Root Entity through Provider
			if (!entity.IsDeleted)
				this.Save(transactionManager, entity);
			
			//used to hold DeepSave method delegates and fire after all the local children have been saved.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			//Fire all DeepSave Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			
			// Save Root Entity through Provider, if not already saved in delete mode
			if (entity.IsDeleted)
				this.Save(transactionManager, entity);
				

			deepHandles = null;
						
			return true;
		}
		#endregion
	} // end class
	
	#region SanPatternChildEntityTypes
	
	///<summary>
	/// Enumeration used to expose the different child entity types 
	/// for child properties in <c>BesAsm.MasterData.Entities.SanPattern</c>
	///</summary>
	public enum SanPatternChildEntityTypes
	{
		
		///<summary>
		/// Composite Property for <c>Status</c> at StatusSource
		///</summary>
		[ChildEntityType(typeof(Status))]
		Status,
		}
	
	#endregion SanPatternChildEntityTypes
	
	#region SanPatternFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;SanPatternColumn&gt;"/> class
	/// that is used exclusively with a <see cref="SanPattern"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class SanPatternFilterBuilder : SqlFilterBuilder<SanPatternColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the SanPatternFilterBuilder class.
		/// </summary>
		public SanPatternFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the SanPatternFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public SanPatternFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the SanPatternFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public SanPatternFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion SanPatternFilterBuilder
	
	#region SanPatternParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;SanPatternColumn&gt;"/> class
	/// that is used exclusively with a <see cref="SanPattern"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class SanPatternParameterBuilder : ParameterizedSqlFilterBuilder<SanPatternColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the SanPatternParameterBuilder class.
		/// </summary>
		public SanPatternParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the SanPatternParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public SanPatternParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the SanPatternParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public SanPatternParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion SanPatternParameterBuilder
	
	#region SanPatternSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;SanPatternColumn&gt;"/> class
	/// that is used exclusively with a <see cref="SanPattern"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class SanPatternSortBuilder : SqlSortBuilder<SanPatternColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the SanPatternSqlSortBuilder class.
		/// </summary>
		public SanPatternSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion SanPatternSortBuilder
	
} // end namespace
